import {
	dateFilter
} from './filter'
 /**
  * 获取两日期之间日期列表函数
  * @param {string} stime 开始时间2020-12-01
  * @param {string} etime 开始时间2023-02-03
  * @return {Array} 装有开始时间到结束时间区间的时间数组
  */
 export  function getdiffdate(stime,etime){
     var diffdate = new Array();
     var i=0;
	 function supplement(str){
		 return str.split('-').map(v=>v.padStart(2,0)).join('-')
	 }
	 stime = supplement(stime)
	 etime = supplement(etime)
     while(stime<=etime){
         diffdate[i] = stime;
         var stime_ts = new Date(stime).getTime();
         var next_date = stime_ts + (24*60*60*1000);
         var next_dates_y = new Date(next_date).getFullYear()+'-';
         var next_dates_m = (new Date(next_date).getMonth()+1 < 10)?'0'+(new Date(next_date).getMonth()+1)+'-':(new Date(next_date).getMonth()+1)+'-';
         var next_dates_d = (new Date(next_date).getDate() < 10)?'0'+new Date(next_date).getDate():new Date(next_date).getDate();
         stime = next_dates_y+next_dates_m+next_dates_d;
         i++;
     }
     return (diffdate);
 }
 
 /**
  * 获取开始结束时间参数
  * @param {number,string} id =[number,string]
  */
 export const tagChange = (id) => {
 	let date = new Date()
 	let params = {
 		endTime : dateFilter(date)
 	}
 	if (typeof id === 'number') {
 		let y = date.getFullYear()
 		let m = date.getMonth()+1
 		let d = date.getDate()
 		if(d-id<1){
 			m-=1
 			let dNum = new Date(y, m, 0).getDate()
 			d = dNum - Math.abs(d - id)
 			if(m<1){
 				y-=1
 				m=12
 			}
 		}else{
 			d -=id
 		}
 		params.startTime = dateFilter(new Date(`${y}-${m}-${d}`))
 	} else {
 		let Month = date.getMonth()
 		let year = date.getFullYear()
 		switch (id) {
 			case '本月':
 				params.startTime = `${year}-${Month+1}-1`
 				break;
 			case '上月':
 				if(Month==0){
 					year -= 1
 					Month = 1
 				}
 				let  a = {
 					startTime: dateFilter(new Date(`${year}-${Month}-${1}`)),
 					endTime: dateFilter(new Date(
 						`${year}-${Month}-${new Date(year, Month+1, 0).getDate()}`
 						))
 				}
 				return a
 				break;
 			case '本季':
 				let jdArr = [1, 4, 7, 10]
 				let jd = Math.trunc((Month + 1) / 3)
 				params.startTime = dateFilter(new Date(`${year}-${jdArr[jd]}-1`))
 
 				break;
 			case '本年':
 				params.startTime = dateFilter(new Date(`${year}-1-1`))
 				break;
 			default:
 				break;
 		}
 	}
 	return params
 }

